package pl.us.ij.plugins.segmentation.commands;

/**
 * Created by IntelliJ IDEA.
 * User: pgajdzik
 * Date: Sep 15, 2010
 * Time: 9:04:56 AM
 * To change this template use File | Settings | File Templates.
 */
public class ArrayHelper {
    public static float max( float[] elements ) {
        if ( elements == null ) {
            throw new IllegalArgumentException("It cannot be a null!", new NullPointerException());
        }

        float max = Float.MIN_VALUE;

        for ( int i = 0; i < elements.length; i++ ) {
            if ( elements[i] > max ) {
                max = elements[i];
            }
        }

        return max;
    }

    public static float min( float[] elements ) {
        if ( elements == null ) {
            throw new IllegalArgumentException("It cannot be a null!", new NullPointerException());
        }

        float min = Float.MAX_VALUE;

        for ( int i = 0; i < elements.length; i++ ) {
            if ( elements[i] < min ) {
                min = elements[i];
            }
        }

        return min;
    }

    public static void multiply(float[] elements, float v) {

        for ( int i = 0; i < elements.length; i++ ) {
            elements[ i ] *= v;
        }
    }

    public static void roundMultiply(float[] elements, float v) {
        for ( int i = 0; i < elements.length; i++ ) {
            elements[ i] = Math.round(elements[ i ] * v);
        }
    }
}
